<template>
  <div>
    <div class="strategyFatherBox">
      <el-button type="success" size='small' @click="dialogVisible()" class="addClick">{{$t('添加')}}</el-button>
      <el-button type="danger" size='small' @click="deleteData" class="delClick">{{$t('删除')}}</el-button>
    </div>
    <el-table size='mini' ref="multipleTable" :data="multicastrouteList" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align='center' width="55"></el-table-column>
      <el-table-column prop="id" label="id" align='center' min-width="80">
        <template slot-scope="scope">
          {{scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column prop="inbound_interface" :label="$t('入站接口名称')" align='center' min-width="200"></el-table-column>
      <el-table-column prop="source_ip" :label="$t('源地址')" align='center' min-width="200"></el-table-column>
      <el-table-column prop="group_ip" :label="$t('组播IP')" align='center' min-width="200"></el-table-column>
      <el-table-column prop="outbound_interface" :label="$t('出站接口名称')" align='center' min-width="200"></el-table-column>
      <!-- <el-table-column prop="right" align='center' fixed="right" :label="$t('操作')" width="220">
        <template slot-scope="scope">
          <el-button type="success" plain size="mini" @click="dialogVisible(scope.row)">{{$t('编辑')}}</el-button>
        </template>
      </el-table-column> -->
    </el-table>

    <multicastroute-dialog v-if="multicastrouteDialogVisible" ref="refMulticastrouteDialogVisible"></multicastroute-dialog>
  </div>
</template>
<script>
import { routeMulticastArray, delRouteMulticast } from '@/api/network/route/multicastroute'
import MulticastrouteDialog from './components/MulticastrouteDialog'
export default {
  name: 'Multicastroute',
  components: {
    MulticastrouteDialog
  },
  data () {
    return {
      multicastrouteDialogVisible: false,
      multicastrouteConfigDialogVisible: false,
      multicastrouteList: [],
      // total: 0,
      name: ''
    }
  },
  created () {
    this.listData()
  },
  methods: {
    // 多选按钮
    handleSelectionChange (data) {
      var name = ''
      for (var item of data) {
        if (name === '') {
          name = item.id
        } else {
          name = name + '@#@' + item.id
        }
      }
      this.name = name
    },
    // 列表
    listData () {
      routeMulticastArray().then(res => {
        if (res.status === 0) {
          this.multicastrouteList = res.info
        }
      })
    },
    // 添加按钮表单
    dialogVisible (data) {
      this.multicastrouteDialogVisible = true
      this.$nextTick(() => {
        this.$refs.refMulticastrouteDialogVisible.init(data)
      })
    },
    deleteData () {
      if (this.name) {
        this.$confirm(this.$t('您是否要删除所有选中的数据？'), this.$t('提示'), {
          closeOnClickModal: false,
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          confirmButtonClass: 'confirmButton',
          cancelButtonClass: 'confirmCancelButton',
          type: 'warning'
        }).then(() => {
          delRouteMulticast({ id: this.name }).then(res => {
            if (res.status === 0) {
              this.$message({
                message: this.$t('删除成功'),
                type: 'success'
              })
              this.name = ''
              this.listData()
            }
          })
        })
      } else {
        this.$messages.error(this.$t('请至少选择一条数据进行删除'))
      }
    }
  }
}
</script>
